package com.softWang.common.dataPermission.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import com.softWang.common.dataPermission.context.DataPermissionContextHolder;
@Aspect
@Component // 必须添加 @Component 或 @Service 等注解，让 Spring 管理该类,否则切面不会生效
@Slf4j
public class DataPermissionAspect {

    @Around("@annotation(dataPermission)")
    public Object around(ProceedingJoinPoint joinPoint, DataPermission dataPermission) throws Throwable {
        DataPermissionContextHolder.add(dataPermission);
        try {
            // 执行逻辑
            return joinPoint.proceed();
        } finally {
            DataPermissionContextHolder.remove();
        }
    }

}
